package org.company.box.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.company.box.dao.IEmpleadoDAO;
import org.company.box.model.EmpleadoDTO;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class EmpleadoDAOImpl implements IEmpleadoDAO {


	@Resource
    private SessionFactory sessionFactory;
	
	@Transactional
	public void saveOrUpdate(EmpleadoDTO empleado) {
		sessionFactory.getCurrentSession().saveOrUpdate(empleado);

	}

	@Transactional
	public void delete(EmpleadoDTO empleado) {
		sessionFactory.getCurrentSession().delete(empleado);

	}

	@Transactional(readOnly = true)  
	public List<EmpleadoDTO> listAll() {
		return sessionFactory.getCurrentSession().createCriteria(EmpleadoDTO.class).list();
	}

}
